namespace MSpecTests.WhoCanHelpMe
{
    #region Using Directives

    using global::WhoCanHelpMe.Web.Controllers.Shared.ActionResults;

    using Machine.Specifications;
    using System.Web.Mvc;

    #endregion

    /// <summary>
    /// Exension methods primarily for use in testing ActionResults
    /// </summary>
    public static class ActionResultExtensions
    {
        public static ViewResult IsAViewAnd(this ActionResult result)
        {
            result.ShouldBeOfType(typeof(ViewResult));

            return result as ViewResult;
        }

        public static RedirectResult IsARedirectAnd(this ActionResult result)
        {
            result.ShouldBeOfType(typeof(RedirectResult));

            return result as RedirectResult;
        }

        public static RedirectToRouteResult IsARedirectToARouteAnd(this ActionResult result)
        {
            result.ShouldBeOfType(typeof(RedirectToRouteResult));

            return result as RedirectToRouteResult;
        }

        public static string ControllerName(this RedirectToRouteResult result)
        {
            return result.RouteValues["Controller"].ToString();
        }
        
        public static string ActionName(this RedirectToRouteResult result)
        {
            return result.RouteValues["Action"].ToString();
        }

        public static NotFoundResult ShouldBeANotFoundResult(this ActionResult result)
        {
            result.ShouldBeOfType(typeof(NotFoundResult));

            return result as NotFoundResult;
        }
    }
}